editor
search
challenges
pseudocode
sql
exam q's
resources
PSEUDOCODE
PRO
download
help
buy ($2)
contact
account
login/signup
my favourites
9618 A-Level
2022 Oct/Nov
Paper 21 | Question 8
Syntax Checks
Question PDF
Mark Scheme
Open in Code Editor
Regenerate Starter Code
Open Solution
tn2eHVGKM3k
Jim01Prog.txt
// * Description: Uses the Sieve of Eratosthenes method to find all primes between 2 and n. The method works by assuming all numbers are prime to start with, finding primes, then marking their multiples as not prime. Any number that has hence not been set to not prime when it is checked is therefore a prime // // More info: https://www.geeksforgeeks.org/sieve-of-eratosthenes/ DECLARE limit, primeCount : INTEGER OUTPUT "Output all primes from 2 to n. Enter a value of n" INPUT limit DECLARE isPrime : ARRAY[2:limit] OF BOOLEAN // Initialise array FOR n <-- 2 TO limit isPrime[n] <-- TRUE NEXT n FOR n <-- 2 TO limit IF isPrime[n] = TRUE THEN // Print n if it is prime OUTPUT n primeCount <-- primeCount + 1 // Then mark all its multiples as not prime FOR multiple <-- 2 TO DIV(limit, n) isPrime[n * multiple] <-- FALSE NEXT multiple ENDIF NEXT n OUTPUT "There are " & primeCount & " primes in the range 2-" & limit
Syllabus Syntax Highlighting
Cambridge A-Level 9618
Cambridge IGCSE/O-Level 0478/2210